// --------------------------------------------------------------------
//   name 	: TribalWars Map integration
//   desc 	: Integrates the normal game map with the more useful advanced TribalWarsMap.com
//   version	: Beta v0.1
//   dev 	: JelianSD
// --------------------------------------------------------------------
// DEPENDENCIES
// 	None
// --------------------------------------------------------------------
// CHANGE HISTORY
// 0.1	Initial Release
// --------------------------------------------------------------------

plugins.TWMapIntegration = {
	'enhance_game_map' : function() {
		Pointer = $("table:last").parent().parent().parent().parent();
		Pointer.after("<br /><center><table class='vis' width='400px' align='center' style='border:1px solid black;'><tr><td width='100%' height='100%' align='center'><a href='#' id='mapToggleA' onclick='javascript:toggleMapServer();' title='Toggle map system.'>Switch to TWMaps.com</a><br /></td></tr></table></center>");
		CurrentLocationAjax = ($("table.main").html()).match(/ajaxMapInit\((\d+)\,\ (\d+)/g) + " ";
		var CurrentLocation = new Array();
		CurrentLocation = CurrentLocationAjax.substr(CurrentLocationAjax.indexOf("(")+1).replace(/ /g,"").split(",");
		CurrentLocation[0] = parseInt(CurrentLocation[0]) + 3;
		CurrentLocation[1] = parseInt(CurrentLocation[1]) + 3;
		var TWMIfrH = getValuePlugin('TWMapIFrameHeight');
		var TWMIfrW = getValuePlugin('TWMapIFrameWidth');
		var currentS = getValuePlugin('TWMapIntegrate');
		if(currentS!="TW") {
			Pointer.after("<center><table id='TWMap' class='main' cellspacing='0' cellpadding='0' align='center'><tr><td><iframe width='"+TWMIfrW+"' height='"+TWMIfrH+"' src='http://"+twe.World+".tribalwarsmap.com/?x="+CurrentLocation[0]+"&y="+CurrentLocation[1]+"'></iframe></td></tr></table></center>");
			Pointer.hide();
			$("#mapToggleA").html("Switch to default map");
		};
		setFunc("toggleMapServer", function() {	
			if(currentS=="TW") {
				if($("#TWMap").length>0) {
					Pointer.hide();
					$("#TWMap").show();
				} else {
					Pointer.after("<center><table id='TWMap' class='main' cellspacing='0' cellpadding='0' align='center'><tr><td><iframe width='"+TWMIfrW+"' height='"+TWMIfrH+"' src='http://"+twe.World+".tribalwarsmap.com/?x="+CurrentLocation[0]+"&y="+CurrentLocation[1]+"'></iframe></td></tr></table></center>");
					Pointer.hide();
				}
				currentS = "TWM";
				$("#mapToggleA").html("Switch to default map");
			} else {
				$("#TWMap").hide();
				Pointer.show();
				currentS = "TW";
				$("#mapToggleA").html("Switch to TWMaps.com");
			}
		});
	},
	'info' : {
		'mandatory' : false,
		'name' : "Integrate Tribal Wars Map.com for the English Servers",
		'desc' : "Adds the TWM tool onto the normal map so people can switch to the much more sleek and nice TWM map system :)",
		'version' : "Beta v0.1",
		'dev' : "JelianSD"
	},
	'variables' : {
		'desc':["TW for default map type, TWN for the TWmaps.com map type.","The height of the frame the map is set in.","The width of the frame the map is set in."],
		'tooltip':["","Will have to change to get rid of scroll bars if you change the default village numbers.","Will have to change to get rid of scroll bars if you change the default village numbers."],
		'TWMapIntegrate':["TW","TWN"],
		'TWMapIFrameHeight':'665',
		'TWMapIFrameWidth':'900'
	}
}
